package com.lovo.auth.controller;

import com.alibaba.fastjson2.JSON;
import com.lovo.auth.dao.IUserDao;
import com.lovo.auth.entity.UserEntity;
import com.lovo.util.CreateToken;
import com.lovo.util.ResultTokenVo;
import com.lovo.vo.ResultVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("auth")
public class UserController {
    @Autowired
    IUserDao userDao;
    @GetMapping("login/{userName}/{password}")
    public ResultVo login(@PathVariable("userName")String userName,
                               @PathVariable("password")String password){
        UserEntity user=
          userDao.findDistinctByUserNameAndPassword(userName,password);
        ResultVo vo=new ResultVo();
   if(null!=user){
      vo.setTag(0);
       user.setPower("findOrder");
      String json= JSON.toJSONString(user);//把对象转换为json字符串
     String token=  CreateToken.getToken(json);
     vo.setToken(token);
    }else {
      vo.setTag(1);
  }
   return vo;
    }
}
